package com.shujia.springboot.controller;

import com.shujia.springboot.common.Result;
import com.shujia.springboot.entity.StuSumScore;
import com.shujia.springboot.service.StuSumScoreService;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController // 将返回的数据变成JSON格式
@RequestMapping("/stuSumScore")
public class StuSumScoreController {
    @Resource
    StuSumScoreService stuSumScoreService;

    @GetMapping("/getAll")
    public Result<List<StuSumScore>> getAll() {
        return Result.success(stuSumScoreService.findAllStuSumScore());
    }

    // /stuSumScore/getAllByPageWithClazzOption?pageSize=10&pageNum=5&clazz=理科六班
    @GetMapping("/getAllByPageWithClazzOption")
    public Result<Page<StuSumScore>> getStuSumScoreByPageWithClazzOption(@RequestParam("pageSize") int pageSize,
                                                                         @RequestParam("pageNum") int pageNum,
                                                                         @RequestParam("clazz") String clazz) {
        Page<StuSumScore> data = stuSumScoreService.getStuSumScoreByPageWithClazzOption(pageSize,pageNum,clazz);
        return Result.success(data);

    }

    // /stuSumScore/page?pageSize=10&pageNum=5 @RequestParam /page
    // /stuSumScore/page/10/5 @PathVariable /page/{pageSize}/{pageNum}
    @GetMapping("/page")
    public Result<Page<StuSumScore>> getStuSumScoreByPage(@RequestParam("pageSize") int pageSize,
                                                          @RequestParam("pageNum") int pageNum) {
        Page<StuSumScore> data = stuSumScoreService.getStuSumScoreByPage(pageSize, pageNum);
        return Result.success(data);

    }

    // /stuSumScore/del/100
    @DeleteMapping("/del/{id}")
    public Result<String> deleteById(@PathVariable("id") int id) {
        stuSumScoreService.deleteById(id);
        return Result.success();
    }

    @PutMapping("/addOrEdit")
    public Result<String> addOrEditStu(@RequestBody StuSumScore stuSumScore) {
        stuSumScoreService.addOrEditStuSumScore(stuSumScore);
        return Result.success();
    }


}
